<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            sort方法进行字母排序  直接用sort()方法
            
            */
            var groupAnagrams = function (strs) {
                let map = new Map()
                let result = []
                for (let i = 0; i < strs.length; i++) {
                    let s = strs[i].split("").sort().join("")
                    if (map.has(s)) {
                        let list = map.get(s)
                        map.set(s, [...list, strs[i]])
                    } else {
                        map.set(s, [strs[i]])
                    }
                }

                for (let [key, value] of map) {
                    result.push(value)
                }
                return result
            }
            groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"])
        </script>
    </body>
</html>
